// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

#include "Import/BDFImport/BulkData/Element/CBARParser.h"

#include "gtest/gtest.h"

#include "DataStructure/Input/Element/BeamCoordOptions.h"
#include "DataStructure/Input/Element/CBARData.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using SG::DataStructure::Common::TOLERANCE;
using namespace SG::DataStructure::FEM;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;
extern std::vector<std::string>          dividedEntryInfo;

TEST (ElementParserTest, CBAR)
{
    DB_SERVICEFACTORY->ClearDatabase ();
    std::vector<std::string> Entry = { "CBAR          10 6110107      53      54      1.      0.      0.BGG     +0000023",
                                       "+0000023                     15.     28.     20.     32.     45.     40." };
    BDF::divideBulkEntry (Entry, dividedEntryInfo);
    SG::Import::BDF::BULKDATA::ParseCBAR (DB_SERVICEFACTORY, dividedEntryInfo);

    // 测试数据
    SG::DataStructure::FEM::CBARData    data;
    std::vector<BeamCoordOptions> const dataGetCoordOptionsTarget{ SG::DataStructure::FEM::BeamCoordOptions::OPTION_B,
                                                                   SG::DataStructure::FEM::BeamCoordOptions::OPTION_G,
                                                                   SG::DataStructure::FEM::BeamCoordOptions::OPTION_G };
    DB_SERVICEFACTORY->get<IElementService> ()->FindByIndex (0, data);

    ASSERT_TRUE (data.m_id == 10);
    ASSERT_TRUE (data.m_pId == 6110107);
    ASSERT_TRUE (data.m_g[0] == 53);
    ASSERT_TRUE (data.m_g[1] == 54);
    ASSERT_TRUE (data.GetCoordOptions () == dataGetCoordOptionsTarget);
    ASSERT_EQ (data.m_go, 0);
    ASSERT_NEAR (data.m_w1a, 15.0, TOLERANCE);
    ASSERT_NEAR (data.m_w2a, 28.0, TOLERANCE);
    ASSERT_NEAR (data.m_w3a, 20.0, TOLERANCE);
    ASSERT_NEAR (data.m_w1b, 32.0, TOLERANCE);
    ASSERT_NEAR (data.m_w2b, 45.0, TOLERANCE);
    ASSERT_NEAR (data.m_w3b, 40.0, TOLERANCE);
    ASSERT_NEAR (data.m_x1, 1.0, TOLERANCE);
    ASSERT_NEAR (data.m_x2, 0.0, TOLERANCE);
    ASSERT_NEAR (data.m_x3, 0.0, TOLERANCE);
}
